import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class RegisterPanel extends JPanel {
	protected JLabel namePrompt;
	protected JLabel passPrompt1;
	protected JLabel servPrompt;
	protected JTextField nameField, emailField;
	protected JPasswordField passField1, passField2;
	protected JComboBox servList;
	protected Color bColor = new Color(43, 43, 43);
	protected Color tColor = Color.white;
	protected JButton login, cancel, register;
	protected Output o;

	public RegisterPanel(Output arg) {
		o = arg;
		o.registerPanel = this;

		this.setLayout(new BorderLayout());
		this.setBackground(bColor);

		JPanel jpn = new JPanel();
		jpn.setBackground(bColor);
		jpn.setBorder(BorderFactory.createEmptyBorder(10, 18, 10, 0));
		jpn.setLayout(new BorderLayout());
		this.add(jpn, BorderLayout.NORTH);

		JLabel jl = new JLabel("  GENERALS ");
		jl.setFont(new Font("Arial", Font.BOLD, 20));
		jl.setForeground(Color.white);
		jpn.add(jl, BorderLayout.NORTH);

		JPanel jp = new JPanel();
		jp.setBackground(Color.white);
		jp.setLayout(new GridBagLayout());
		this.add(jp, BorderLayout.CENTER);

		GridBagConstraints c = new GridBagConstraints();
		c.fill = GridBagConstraints.HORIZONTAL;

		namePrompt = new JLabel("Username:");
		c.gridx = 0;
		c.gridy = 0;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(namePrompt, c);
		nameField = new JTextField();
		nameField.setPreferredSize(new Dimension(100, 22));
		c.gridx = 1;
		c.gridy = 0;
		jp.add(nameField, c);

		passPrompt1 = new JLabel("Password:");
		c.gridx = 0;
		c.gridy = 1;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(passPrompt1, c);
		passField1 = new JPasswordField();
		passField1.setPreferredSize(new Dimension(200, 22));
		c.gridx = 1;
		c.gridy = 1;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(passField1, c);

		JLabel passPrompt2 = new JLabel("Repeat Password:");
		c.gridx = 0;
		c.gridy = 2;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(passPrompt2, c);
		passField2 = new JPasswordField();
		passField2.setPreferredSize(new Dimension(100, 22));
		c.gridx = 1;
		c.gridy = 2;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(passField2, c);

		JLabel emailPrompt = new JLabel("Email:");
		c.gridx = 0;
		c.gridy = 3;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(emailPrompt, c);
		emailField = new JTextField();
		emailField.setPreferredSize(new Dimension(100, 22));
		c.gridx = 1;
		c.gridy = 3;
		c.insets = new Insets(10, 10, 5, 10);
		jp.add(emailField, c);

		JPanel jpl = new JPanel();
		jpl.setBackground(bColor);
		jpl.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 5));
		jpl.setLayout(new BorderLayout());
		this.add(jpl, BorderLayout.SOUTH);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout());
		buttonPanel.setBackground(bColor);
		jpl.add(buttonPanel, BorderLayout.EAST);

		register = new JButton("Register");
		register.setPreferredSize(new Dimension(85, 25));
		register.addActionListener(new RegisterListener());
		buttonPanel.add(register);
		cancel = new JButton("Cancel");
		cancel.setPreferredSize(new Dimension(85, 25));
		cancel.addActionListener(new CancelListener());
		buttonPanel.add(cancel);
		
		
		
		
		nameField.addKeyListener(new AreaKeyListener());
		emailField.addKeyListener(new AreaKeyListener());
		passField2.addKeyListener(new AreaKeyListener());
	}

	private class AreaKeyListener implements KeyListener {
		public void keyTyped(KeyEvent e) {
		}

		public void keyPressed(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER) {
			}
		}

		public void keyReleased(KeyEvent e) {
			if (e.getKeyCode() == KeyEvent.VK_ENTER)
				o.register(nameField.getText(), passField1.getText(),
						passField2.getText(), emailField.getText());
		}
	}

	private class CancelListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			o.registerFrame.setVisible(false);
			o.loginFrame.setVisible(true);
		}
	}

	private class RegisterListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			o.register(nameField.getText(), passField1.getText(), passField2
					.getText(), emailField.getText());
		}
	}

}
